<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-product-edit" >
			<input name="id" type="hidden" th:field="*{product.id}" />
			<h4>编辑产品基本信息</h4>
			<br>
			<hr>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label"><span style="color: red; ">*</span>产品名称：</label>
						<div class="col-sm-8">
							<input class="form-control" placeholder="请输入产品名称" type="text" name="productName" id="productName" required th:field="*{product.productName}">
						</div>
					</div>
				</div>
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label"><span style="color: red; ">*</span>归属平台：</label>
						<div class="col-sm-8">
							<div class="input-group" style="width: 100%">
								<select class="form-control m-b" name="productDeptId" id ="productDeptId" th:field="*{product.productDeptId}" >
								<option th:each="g : ${allDept}"
										th:selected="${g.deptId eq product.productDeptId }"
										th:value="${g.deptId}" th:text="${g.deptName}">
								</option>
								</select>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label"><span style="color: red; ">*</span>归属店铺：</label>
						<div class="col-sm-8">
							<div class="input-group" style="width: 100%">
								<select class="form-control m-b" name="productShopId" id ="productShopId" th:field="*{product.productShopId}"  >
									<option th:each="g : ${allShop}"
											th:selected="${g.id eq product.productShopId }"
											th:value="${g.id}" th:text="${g.shopName}">
									</option>
								</select>
							</div>
						</div>
					</div>
				</div>

				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label"><span style="color: red; ">*</span>赠品：</label>
						<div class="col-sm-8">
							<div class="input-group" style="width: 100%">
								<select class="form-control m-b" id="productGiftId" name="productGiftId" required th:field="*{product.productGiftId}" placeholder="请选择赠品" >
									<option th:each="g : ${allGift}"
											th:selected="${g.id eq product.productGiftId }"
											th:value="${g.id}" th:text="${g.giftName}">
									</option>
								</select>
							</div>
						</div>
					</div>
				</div>

			</div>

				<div class="row">
					<div class="col-sm-6">
						<div class="form-group">
							<label class="col-sm-4 control-label"><span style="color: red; ">*</span>成本：</label>
							<div class="col-sm-8">
								<input class="form-control" placeholder="请输入成本" type="number" name="productCost" id="productCost" required th:field="*{product.productCost}">
							</div>
						</div>
					</div>

				</div>
			<br>

		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script type="text/javascript">
        var prefix = ctx + "product/product";

        //根据选择的平台获取店铺
        $("#productDeptId").on('change',function(){

            $.ajax({
                type: "POST",
                url: prefix +'/selectByDeptId?id='+$("#productDeptId").val(),
                async: false,
                contentType : 'application/json;charset=utf-8',
                traditional:true,
                success : function(data) {
                    var html="<option value=''>请选择归属店铺</opinion>";;
                    for(var i=0;i<data.length;i++){
                        html+="<option value='"+data[i].id+"'>"+data[i].shopName + "</opinion>";

                    }
                    $("#productShopId").empty().append(html);
                },
                error:function(e) {
                    console.info(e);
                }
            });
        })

		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/editProduct", $('#form-product-edit').serialize());
	        }
	    }
	</script>
</body>
</html>
